import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import { viteStaticCopy } from 'vite-plugin-static-copy'

const antdResolver = () => {
  return Components({
    resolvers: [
      AntDesignVueResolver({
        importStyle: false
      })
    ]
  })
}

const viteCopyPlugin = () => {
  return  viteStaticCopy({  
    targets: [  
      { src: 'resources/*', dest: '' },  
    ],  
  })
}

const alias = {
  '@': resolve('src'),
  '@main': resolve('src/main'),
  '@renderer': resolve('src/renderer/src')
}

export default defineConfig({
  main: {
    resolve: {
      alias
    },
    plugins: [
      externalizeDepsPlugin(),
      viteCopyPlugin()
    ]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias
    },
    plugins: [
      vue(),
      antdResolver()
    ]
  }
})
